package svgCanvas.Rectangle;

import java.awt.Point;

/**
 * class rectangle creator creates rectangle from coordinates on canvas
 * @author Martin
 */
public class RectangleCreator {
    /**
     * Method converts coordinates of mouse drag into svg rectangle
     * @param dragStart where user mouse drag started
     * @param dragEnd point where user mouse drag ended
     * @return rectangle to be added to svg file
     */
    public Rectangle CreateRectangleFromCoordinates(Point dragStart, Point dragEnd)
    {
        if(dragStart.x <= dragEnd.x && dragStart.y <= dragEnd.y)
        {
            return new Rectangle(dragStart.x, dragStart.y, dragEnd.x - dragStart.x, dragEnd.y - dragStart.y);
        }
        else if(dragStart.x <= dragEnd.x && dragStart.y >= dragEnd.y)
        {
            return new Rectangle(dragStart.x, dragEnd.y, dragEnd.x - dragStart.x,dragStart.y - dragEnd.y );
        }
        else if(dragStart.x >= dragEnd.x && dragStart.y <= dragEnd.y)
        {
            return new Rectangle(dragEnd.x, dragStart.y, dragStart.x - dragEnd.x,dragEnd.y - dragStart.y );
        }
        else
        {
            return new Rectangle(dragEnd.x, dragEnd.y, dragStart.x - dragEnd.x,dragStart.y - dragEnd.y );
        }
    }
}
